import time
from selenium import webdriver
from selenium.webdriver import Keys

options = webdriver.ChromeOptions()
options.add_argument("--window-size=1920,1080")
driver = webdriver.Chrome(options=options)

driver.get("https://seiyria.com/bootstrap-slider/#example-7")

CHECKBOX_LOCATOR = ("xpath", "//input[@id='ex7-enabled']")
SLIDER_LOCATOR = ("xpath", "//div[@id='example-7']//div[@role='slider'][1]")

driver.find_element(*CHECKBOX_LOCATOR).click()
time.sleep(1)
slider = driver.find_element(*SLIDER_LOCATOR)


def move_slider(slider, target_value):
    """
    Описание для слайдера

    Args:
        slider (WebElement): Элемент слайдера
        target_value (int): Целевое значение, на которое нужно переместить слайдер
    """
    min_value = int(slider.get_attribute("aria-valuemin"))
    max_value = int(slider.get_attribute("aria-valuemax"))
    target_value = max(min_value, min(max_value, target_value))

    steps = abs(target_value - int(slider.get_attribute("aria-valuenow")))

    for _ in range(steps):
        slider.send_keys(
            Keys.ARROW_RIGHT if target_value > int(slider.get_attribute("aria-valuenow")) else Keys.ARROW_LEFT)

    assert int(slider.get_attribute("aria-valuenow")) == target_value


move_slider(slider, 0)
time.sleep(1)
move_slider(slider, 10)
time.sleep(1)
move_slider(slider, 20)
time.sleep(1)
